package com.lx.hashcode;

import java.util.TreeSet;
import java.util.function.Consumer;

public class Treeset {
    public static void main(String[] args) {
        TreeSet<Integer> ts = new TreeSet<>();
//        有序，不重复
        ts.add(5);
        ts.add(8);
        ts.add(4);
        System.out.println(ts.add(4));
        ts.add(11);
        System.out.println(ts);
        ts.forEach((integer) ->System.out.println(integer));

//        底层是红黑树实现
        TreeSet<student> ts2 = new TreeSet<>();
        student s1 = new student("zhangsan",26);
        student s2 = new student("lisi",24);
        student s3 = new student("wangwu",25);
        ts2.add(s1);
        ts2.add(s2);
        ts2.add(s3);
        ts2.forEach(new Consumer<student>() {
            @Override
            public void accept(student student) {
                System.out.println(student);
            }
        });
    }
}
